import net.sf.json.JSONArray;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/uploadFile")
public class uploadFileServlet extends HttpServlet {


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("uploadFileServlet...");
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        // 检测是否为多媒体上传
        if (!ServletFileUpload.isMultipartContent(request)) {
            // 如果不是则停止
            PrintWriter writer = response.getWriter();
            writer.println("uploadFileServlet========Error: 表单必须包含 enctype=multipart/form-data");
            writer.flush();
            return;
        }


//        UploadUtil data =new UploadUtil();
//        List<List<List<String>>> datalist =  data.upload(request);
//            System.out.println("datalist: "+datalist);
//            out.println(datalist);
//
//
//
//        System.out.println("main...........");


        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try{
                    Thread.sleep(10000);
                    System.out.println("liee");
                    List<List<List<String>>> datalist = new ReadExcelUtils().read("F:\\Web\\后台\\runook_Servlet\\out\\artifacts\\runook_Servlet_war_exploded\\uploadFile\\测试.xlsx");
                    if (datalist == null) {
                        System.out.println("datalist is null");
                    }
                    if (datalist.size() ==0){
                        System.out.println("datalist size 0");
                    }
//        System.out.println("--------obj----------"+obj);
                    out.println(datalist);
                } catch (Exception e){
                    e.printStackTrace();
                }
            }
        });
        thread.start();


    }


//
}


